<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ include file="/include/taglibs.jsp" %>
<html>
<head>
    <%@include file="/include/header.html" %>
    <script type="text/javascript" src="${ctx}/appjs/market/rechargeDiscount.js"></script>
    <link rel="stylesheet" href="${ctx}/statics/css/update.css">
    <link rel="stylesheet" href="${ctx}/statics/css/common.css">
    <link rel="stylesheet" href="${ctx}/libjs/plugins/laydate/laydate.css">
    <script src="${ctx}/libjs/plugins/laydate/laydate.js"></script>
    <style>
        .layui-disabled, .layui-disabled:hover {
            color: #000 !important;
        }
    </style>
</head>

<script type="text/javascript">
    $('#topLink', window.parent.document).html(function (i, origText) {
        return '<ol class="breadcrumb">' +
            '<li class="breadcrumb-item">' +
            '<a href="">主页</a>' +
            '</li>' +
            '<li class="breadcrumb-item">' +
            '<a>运营管理</a>' +
            '</li>' +
            '<li class="breadcrumb-item">' +
            '<strong>编辑充值送</strong>' +
            '</li>' +
            '<li class="breadcrumb-item">' +
            '<a href="javascript:window.history.back()"><i class="fa fa-times"></i> 返回</a>' +
            '</li>' +
            '</ol>';
    });

</script>

<body class="gray-bg">
<div class="wrapper wrapper-content ">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <div class="columns pull-left">
                        <h5 class="font-bold">编辑充值送</h5>
                    </div>
                    <div class="ibox-tools">
                        <a class="close-link">
                            <i class="fa fa-times"></i>
                        </a>
                    </div>
                </div>

                <div class="ibox-content">
                    <form class="form-horizontal m-t  layui-form" id="frmRechargeDiscount">
                        <input type="hidden" id="marketActivityId" value="${marketActivityVo.marketActivityId}">
                        <input type="hidden" name="imgType" id="imgType" value="4">
                        <div class="form-group row">
                            <label class="col-sm-3 col-form-label text-right">活动名称：</label>
                            <div class="col-sm-3">
                                <input class="form-control" name="activityName" id="activityName"
                                       value="${marketActivityVo.activityName}" readonly>
                            </div>
                        </div>

                        <div class="form-group row">
                            <label class="col-sm-3 col-form-label text-right">赠送对象：</label>
                            <div class="col-sm-5">
                                <input type="radio" class="form-control" name="sendType"
                                       <c:if test="${marketActivityVo.sendType eq '4'}">checked="checked"</c:if>
                                       lay-filter="sendType" title="全部用户" value="4">
                                <input type="radio" class="form-control" name="sendType"
                                       <c:if test="${marketActivityVo.sendType eq '2'}">checked="checked"</c:if>
                                       lay-filter="sendType" title="普通用户" value="2">
                                <input type="radio" class="form-control" name="sendType"
                                       <c:if test="${marketActivityVo.sendType eq '3'}">checked="checked"</c:if>
                                       lay-filter="sendType" title="企业用户" value="3">
                            </div>
                        </div>

                        <div class="form-group row">
                            <label class="col-sm-3 col-form-label text-right">参与的支付方式：</label>
                            <div class="col-sm-5">
                                <input type="checkbox" class="form-control" name="aliPay"
                                       lay-filter="aliPay" title="支付宝" value="1"
                                       <c:if test="${marketActivityVo.aliPay eq '1'}">checked="checked"</c:if>  >
                                <input type="checkbox" class="form-control" name="wxPay"
                                       lay-filter="wxPay" title="微信" value="1"
                                       <c:if test="${marketActivityVo.wxPay eq '1'}">checked="checked"</c:if> >
                                <input type="checkbox" class="form-control" name="unPay"
                                       lay-filter="unPay" title="银联" value="1"
                                       <c:if test="${marketActivityVo.unPay eq '1'}">checked="checked"</c:if> >
                                <input type="checkbox" class="form-control" name="abcPay"
                                       lay-filter="abcPay" title="农行" value="1"
                                       <c:if test="${marketActivityVo.abcPay eq '1'}">checked="checked"</c:if> >
                            </div>
                        </div>

                        <div class="form-group row">
                            <label class="col-sm-3 col-form-label text-right">客户端支持：</label>
                            <div class="col-sm-5">
                                <input type="checkbox" class="form-control" name="isApp"
                                       lay-filter="isApp" title="App" value="1"
                                       <c:if test="${marketActivityVo.isApp eq '1'}">checked="checked"</c:if> >
                                <input type="checkbox" class="form-control" name="isWx"
                                       lay-filter="isWx" title="微信公众号" value="1"
                                       <c:if test="${marketActivityVo.isWx eq '1'}">checked="checked"</c:if> >
                            </div>
                        </div>

                        <div class="form-group row">
                            <label class="col-sm-3 col-form-label text-right">同个用户最多享受优惠次数：</label>
                            <div class="col-sm-3">
                                <input class="form-control" id="maxDiscountCount" min="1" type="number"
                                       oninput="this.value = this.value.replace(/[^0-9]/g, '');"
                                       value="${marketActivityVo.maxDiscountCount}"
                                       name="maxDiscountCount">
                            </div>
                            <div class="col-sm-2 layui-form-mid layui-word-aux">次</div>
                        </div>

                        <div class="form-group row">
                            <label class="col-sm-3 col-form-label text-right">优惠时间：</label>
                            <div class="col-sm-2">
                                <input class="form-control" id="beginTime" name="beginTime"
                                       value="<fmt:formatDate value="${marketActivityVo.beginTime}" pattern="yyyy-MM-dd HH:mm:ss" />"
                                       readonly>
                            </div>
                            <div class="col-sm-0.5">
                                <span>至</span>
                            </div>
                            <div class="col-sm-2">
                                <input class="form-control" id="endTime" name="endTime"
                                       value="<fmt:formatDate value="${marketActivityVo.endTime}" pattern="yyyy-MM-dd HH:mm:ss" />"
                                       readonly>
                            </div>
                        </div>
                        <div class="form-group row">
                            <label class="col-sm-3 col-form-label text-right">充值送类型：</label>
                            <div class="col-sm-4">
                                <input type="radio" class="form-control" name="rewardType" disabled
                                       <c:if test="${marketActivityVo.rewardType eq '2'}">checked="checked" </c:if>
                                       lay-filter="rewardType" title="充值送优惠券" value="2">
                                <input type="radio" class="form-control" name="rewardType" disabled
                                <c:if test="${marketActivityVo.rewardType eq '4'}">checked="checked"</c:if>
                                lay-filter="rewardType" title="充值减免" value="4">
                            </div>
                        </div>
                        <div class="form-group row">
                            <label class="col-sm-3 col-form-label text-right"></label>
                            <div class="col-sm-9">
                                <c:choose>
                                    <c:when test="${marketActivityVo.rewardType eq '2'}">
                                        <div class="layui-card coupon-layui-card">
                                            <c:forEach items="${marketActivityVo.list}" var="item" varStatus="index">
                                                <div class="layui-card-body coupon-layui-card-body col-sm-10 row">
                                                    <div class=" layui-form-mid layui-word-aux">满</div>
                                                    <div class="col-sm-3">
                                                        <input class="form-control requireAmount" disabled
                                                               value="${item.requireAmount}" min="0" type="number"
                                                               onkeyup="num(this)">
                                                    </div>
                                                    <div class=" layui-form-mid layui-word-aux">赠送</div>
                                                    <div class="col-sm-2">
                                                        <input class="form-control sendCount" min="1" disabled
                                                               value="${item.sendCount}"
                                                               oninput="this.value = this.value.replace(/[^0-9]/g, '');"
                                                               type="number">
                                                    </div>
                                                    <div class=" layui-form-mid layui-word-aux">张</div>
                                                    <div class="col-sm-1 layui-form-mid layui-word-aux"></div>
                                                    <div class="col-sm-5">
                                                        <select class="form-control ticketTypeId" disabled>
                                                                ${item.ticketSelect}
                                                        </select>
                                                    </div>
                                                        <%--<a class="btn btn-danger  btn-sm del_btn delList">删除</a>--%>
                                                </div>
                                            </c:forEach>
                                        </div>
                                        <div class="layui-card cash-layui-card hide">
                                            <div class="layui-card-body cash-layui-card-body col-sm-6 row">
                                                <div class=" layui-form-mid layui-word-aux">满</div>
                                                <div class="col-sm-6">
                                                    <input class="form-control requireAmount" min="0" type="number"
                                                           onkeyup="num(this)">
                                                </div>
                                                <div class=" layui-form-mid layui-word-aux">减</div>
                                                <div class="col-sm-4">
                                                    <input class="form-control sendAmount" min="1" type="number"
                                                           oninput="this.value = this.value.replace(/[^0-9]/g, '');">
                                                </div>
                                                <div class=" layui-form-mid layui-word-aux">元</div>
                                                    <%--<a class="btn btn-danger  btn-sm del_btn delList">删除</a>--%>
                                            </div>
                                        </div>
                                    </c:when>
                                    <c:otherwise>
                                        <div class="layui-card coupon-layui-card hide">
                                            <div class="layui-card-body coupon-layui-card-body col-sm-10 row">
                                                <div class=" layui-form-mid layui-word-aux">满</div>
                                                <div class="col-sm-3">
                                                    <input class="form-control requireAmount"
                                                           value="${item.requireAmount}" min="0" type="number"
                                                           onkeyup="num(this)">
                                                </div>
                                                <div class=" layui-form-mid layui-word-aux">减</div>
                                                <div class="col-sm-2">
                                                    <input class="form-control sendCount" min="1"
                                                           value="${item.sendCount}"
                                                           oninput="this.value = this.value.replace(/[^0-9]/g, '');"
                                                           type="number">
                                                </div>
                                                <div class=" layui-form-mid layui-word-aux">张</div>
                                                <div class="col-sm-1 layui-form-mid layui-word-aux"></div>
                                                <div class="col-sm-5">
                                                    <select class="form-control ticketTypeId hideTicketSelect"
                                                            id="ticketTypeId">
                                                    </select>
                                                </div>
                                                    <%--<a class="btn btn-danger  btn-sm del_btn delList">删除</a>--%>
                                            </div>
                                        </div>
                                        <div class="layui-card cash-layui-card ">
                                            <c:forEach items="${marketActivityVo.list}" var="item" varStatus="index">
                                                <div class="layui-card-body cash-layui-card-body col-sm-6 row">
                                                    <div class=" layui-form-mid layui-word-aux">满</div>
                                                    <div class="col-sm-6">
                                                        <input class="form-control requireAmount" disabled
                                                               value="${item.requireAmount}" min="0" type="number"
                                                               onkeyup="num(this)">
                                                    </div>
                                                    <div class=" layui-form-mid layui-word-aux">减</div>
                                                    <div class="col-sm-4">
                                                        <input class="form-control sendAmount" disabled
                                                               value="${item.sendAmount}" min="1" type="number"
                                                               oninput="this.value = this.value.replace(/[^0-9]/g, '');">
                                                    </div>
                                                    <div class=" layui-form-mid layui-word-aux">元</div>
                                                        <%--<a class="btn btn-danger  btn-sm del_btn delList">删除</a>--%>
                                                </div>
                                            </c:forEach>
                                        </div>
                                    </c:otherwise>
                                </c:choose>


                                <%--<a class="btn btn-primary btn-sm addList" onclick="rechargeDiscount.addList()"--%>
                                <%--style="margin-top: 3px;color: #fff">增加优惠项</a>--%>
                            </div>
                        </div>
                        <div class="form-group row">
                            <label class="col-sm-3 col-form-label text-right"></label>
                            <div class="layui-form-mid layui-word-aux" style="padding-left: 15px !important;">
                                注意事项：<br/>
                                1、两项填写才生效，赠送部分只能是正整数>0;例如：充值满200，赠送10张 端午节优惠券（满30减5）<br/>
                                2、设置的优惠项满减金额请按照从小到大的顺序填写
                            </div>
                        </div>
                        <div class="form-group row">

                            <label class="col-sm-3 col-form-label text-right">其他说明：</label>
                            <div class="col-sm-3">
                                <textarea class="form-control" id="remark"
                                          name="remark">${marketActivityVo.remark}</textarea>
                            </div>
                        </div>
                        <div class="couponHtml hide"></div>

                        <div class="form-group">
                            <div class="col-sm-3 col-sm-offset-8 text-right">
                                <button type="submit" class="btn btn-primary">提交</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">

    layui.use(['form', 'jquery', 'tree', 'laydate', 'util'], function () {

        var form = layui.form;
        var $ = layui.jquery;
        //打折与立减切换
        form.on("radio(rewardType)", function (data) {
            if ($(this).val() == "2") {
                $(".coupon-layui-card").removeClass("hide");
                $(".cash-layui-card").addClass("hide");
            } else if ($(this).val() == "4") {
                $(".coupon-layui-card").addClass("hide");
                $(".cash-layui-card").removeClass("hide");
            }
        });

    })
    $(function () {
        $(".ibox-content").css("height", $(window).height() - 80);
        //查询充值送优惠券
        $.ajax({
            "type": "POST",
            "url": prefix + "/selectTicketType",
            "data": {},
            "success": function (data) {
                var str = '';
                for (var i = 0; i < data.data.length; i++) {
                    str += "<option value=" + data.data[i].ticketTypeId + " >" + data.data[i].ticketName + "</option>"
                }
                $(".couponHtml").html(str);
                $(".hideTicketSelect").append(str);
                layui.use('form', function () {  //此段代码必不可少
                    var form = layui.form;
                    form.render();
                });
            }
        })
    })

    var start = {
        elem: '#beginTime',
        format: 'YYYY-MM-DD hh:mm:ss',
        // theme: '#3195f0',
        // min: laydate.now(), //设定最小日期为当前日期
        // max: '2099-06-16 23:59:59', //最大日期
        istime: true,
        istoday: false,
        choose: function (datas) {
            // $("#endTime").val("")
            end.min = datas
        }
    };
    var end = {
        elem: '#endTime',
        format: 'YYYY-MM-DD hh:mm:ss',
        // theme: '#3195f0',
        // min: laydate.now(),
        // max: '2099-06-16 23:59:59',
        istime: true,
        istoday: false,
        choose: function (datas) {
            start.max = datas; //结束日选好后，重置开始日的最大日期
        }
    };
    laydate(start);
    laydate(end);
    laydate.skin('molv');//皮肤

    addRechargeDiscount.init();
</script>
</body>
</html>
